package com.ymatou.iapi.userservice.testcase;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.userservice.parameter.LoinidChangCountBean;
import com.ymatou.iapi.userservice.parameter.SetNickNameDtoBean;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.LoinidChangCountCall;
import com.ymatou.iapi.userservice.service.SetNickNameDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.utils.TestDataManager;

/**
 * 查询登录ID修改的次数Test FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_LoinidChangCount {
	private static LoinidChangCountBean loinidchangcountBean;
	private static LoinidChangCountCall loinidchangcountCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询登录ID修改的次数Test");
	}

	@Before
	public void caseUp() {
		loinidchangcountBean = new LoinidChangCountBean();
		loinidchangcountCall = new LoinidChangCountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(loinidchangcountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	private Calendar getNow() {
		return Calendar.getInstance();
	}

	private static final String YMD = "yyyy-MM-dd";

	private static String calendar2YMDString(Calendar calendar) {
		return new SimpleDateFormat(YMD).format(calendar.getTime());
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LoinidChangCount_001() {
		Logger.start(true, "查询登录ID修改的次数(0次),成功");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);

			Date BeginTime = new SimpleDateFormat("yyyy-MM-dd").parse("2016-10-01");
			Date EndTime = new SimpleDateFormat("yyyy-MM-dd").parse("2016-12-01");
			loinidchangcountBean.setUserId(uid);
			loinidchangcountBean.setBeginTime(BeginTime);
			loinidchangcountBean.setEndTime(EndTime);
			loinidchangcountCall.setData(loinidchangcountBean);
			loinidchangcountCall.callService();

			Logger.verifyEquals("true", loinidchangcountCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", loinidchangcountCall.getString("ResponseCode"), "验证ResponseCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

//	@Test
//	@Category({ P1.class })
//	@TestCase
//	public void Tc_LoinidChangCount_002() {
//		Logger.start(true, "查询登录ID修改的次数(n次),成功");
//		try {
//			CreateUserReq cur = new CreateUserReq();
//			cur = JUserCallService.initCreateUserBean(cur);
//			Integer uid = JUserCallService.createUserCall(cur);
//			SetNickNameDtoBean setnicknamedtobean = new SetNickNameDtoBean();
//			SetNickNameDtoCall setnicknamedtocall = new SetNickNameDtoCall();
//			int count = (int) (Math.random() * 10);
//			for (int i = 0; i < count; i++) {
//				String newNickName = TestDataManager.getRandomNum(10) + "_nickName";
//				setnicknamedtobean.setNickName(newNickName);
//				setnicknamedtobean.setUserId(uid);
//				setnicknamedtocall.setData(setnicknamedtobean);
//				setnicknamedtocall.callService();
//			}
//
//			Date BeginTime = new SimpleDateFormat("yyyy-MM-dd").parse("2016-12-01");
//			Date EndTime = new SimpleDateFormat("yyyy-MM-dd").parse("2017-12-30");
//			loinidchangcountBean.setUserId(uid);
//			loinidchangcountBean.setBeginTime(BeginTime);
//			loinidchangcountBean.setEndTime(EndTime);
//			loinidchangcountCall.setData(loinidchangcountBean);
//			loinidchangcountCall.callService();
//
//			Logger.verifyEquals(count,
//					loinidchangcountCall.getJsonObject().get("Result").getAsJsonObject().get("count").getAsInt(),
//					"验证count");
//			Logger.verifyEquals("true", loinidchangcountCall.getString("Success"), "验证Success");
//			Logger.verifyEquals("200", loinidchangcountCall.getString("ResponseCode"), "验证ResponseCode");
//
//		} catch (Exception e) {
//			Logger.fail(e);
//		}
//	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_LoinidChangCount_003() {
		Logger.start(true, "不传uid,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);

			Date BeginTime = new SimpleDateFormat("yyyy-MM-dd").parse("2016-10-01");
			Date EndTime = new SimpleDateFormat("yyyy-MM-dd").parse("2016-12-01");
			// loinidchangcountBean.setUserId(uid);
			loinidchangcountBean.setBeginTime(BeginTime);
			loinidchangcountBean.setEndTime(EndTime);
			loinidchangcountCall.setData(loinidchangcountBean);
			loinidchangcountCall.callService();

			Logger.verifyEquals("false", loinidchangcountCall.getString("Success"), "验证Success");
			Logger.verifyEquals("100", loinidchangcountCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyIsContains("userid must gte", loinidchangcountCall.getString("LastErrorMessage"),
					"验证LastErrorMessage");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}
